/**
 * Bun Example for ProtoActor-TS
 * 
 * This is a minimal example that demonstrates using ProtoActor-TS with Bun.
 * 
 * To run this example:
 * ```
 * bun run examples/bun-example.ts
 * ```
 */

import { Actor, ActorSystem, Context, Props } from '../src';

// Define a simple actor
class HelloActor implements Actor {
  receive(context: Context): void {
    const message = context.message();
    
    if (typeof message === 'string') {
      console.log(`Received message: ${message}`);
      // No response needed for this simple example
    } else {
      console.log('Received unknown message type');
    }
  }
}

// Main function
async function runBunExample() {
  console.log('Starting Bun example...');
  
  try {
    // Create actor system
    const system = new ActorSystem();
    
    // Create actor
    const props = Props.fromProducer(() => new HelloActor());
    const pid = system.root.spawn(props);
    
    // Send a message
    console.log('Sending message to actor...');
    system.root.send(pid, 'Hello from Bun!');
    
    // Wait a moment to allow processing
    await new Promise(resolve => setTimeout(resolve, 100));
    
    // Terminate the actor system
    console.log('Terminating actor system...');
    await system.terminate();
    console.log('Actor system terminated');
  } catch (error) {
    console.error('Error in Bun example:', error);
  }
}

// Run the example
runBunExample().catch(console.error);

export { runBunExample }; 